package com.ssyc.gsk_master.adapter;

import android.content.Context;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ssyc.common.adapter.CommonAdapter;
import com.ssyc.common.adapter.ViewHolder;
import com.ssyc.common.utils.UiUtils;
import com.ssyc.gsk_master.R;
import com.ssyc.gsk_master.bean.ClassInfo;

import net.lucode.hackware.magicindicator.buildins.UIUtil;

import java.util.List;

/**
 * Created by Administrator on 2018/6/25 0025.
 */

public class ClassGvAdapter extends CommonAdapter<ClassInfo.ListBean> {
    private Context context;
    RelativeLayout.LayoutParams lpTv;

    public ClassGvAdapter(Context context, List<ClassInfo.ListBean> datas, int layoutId) {
        super(context, datas, layoutId);
        this.context = context;
        int width = (UIUtil.getScreenWidth(context) - UiUtils.dp2px(16 * 2 + 4 * 9)) / 4;
        int height = UiUtils.dp2px(28);
        lpTv = new RelativeLayout.LayoutParams(width, height);
    }

    @Override
    public void convert(ViewHolder holder, ClassInfo.ListBean info) {
        //班级名称
        TextView tvClassName = holder.getView(R.id.tv_class_name);
        tvClassName.setText(info.getName());
        tvClassName.setLayoutParams(lpTv);

        //根绝选中状态来设置背景和文字颜色
        if (info.isSelected()) {
            tvClassName.setBackgroundResource(R.drawable.master_class_selected);
            tvClassName.setTextColor(context.getResources().getColor(R.color.white));
        } else {
            tvClassName.setBackgroundResource(R.drawable.master_class_normal);
            tvClassName.setTextColor(context.getResources().getColor(R.color.coffee));
        }

    }
}
